package com.lyz.redis.vo;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class Result<T> {
    private static final String SUCCESS="成功";
    private static final String ERROR="系统错误";
    private static final String FAIL = "失败";

    private Integer code;
    private String massage;
    private T data;

    public static <T> Result<T> OK(){
        return Result.OK(SUCCESS);
    }

//    public static <T> Result<T> OK(String msg){
//        return Result.OK(msg,null);
//    }

//    public static <T> Result<T> OK(T data){
//        return Result.OK(SUCCESS,data);
//    }
    public static <T> Result<T> OK(String msg){
        return new Result<T>(200,msg,null);
    }

    public static <T> Result<T> FAIL(String msg){
        return Result.FAIL(400,msg);
    }

    public static <T> Result<T> FAIL(Integer code,String msg){
        return new Result<T>(code,msg,null);
    }

    public static <T> Result<T> FAIL(){
        return Result.FAIL(FAIL);
    }

    public static <T> Result<T> ERROR(){
        return Result.ERROR(ERROR);
    }

    public static <T> Result<T> ERROR(String msg){
        return Result.ERROR(500,msg);
    }

    public static <T> Result<T> ERROR(Integer code,String msg){
        return new Result<T>(code,msg, null);
    }

    public Result<T> data(T data){
        this.data = data;
        return this;
    }
}
